/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved.
 * Description: Hmfs-tools resize single unit test
 */

#include <fcntl.h>
#include <fstream>
#include <ctime>

#include "compare.h"
#include "whole_compare.h"
#include "gtest/gtest.h"
#include "hmfs_test_utils.h"
#include "resize_command.h"

using namespace testing;
using namespace testing::ext;

namespace OHOS {
namespace Hmfs {
class ResizeHmfsSingleTest : public testing::Test {
public:
    static void SetUpTestCase();
    static void TearDownTestCase();
    void SetUp() override;
    void TearDown() override;
};

void ResizeHmfsSingleTest::SetUpTestCase()
{
    system("mount -o remount,rw /");
    system("ln -s /system/bin/fsck.f2fs /system/bin/dump.f2fs");
    CmdConfig resizeConfig;
    ResizeCmdParser resizeParser(resizeConfig);
}

void ResizeHmfsSingleTest::TearDownTestCase()
{
   system("rm -rf /system/bin/dump.f2fs");
}

void ResizeHmfsSingleTest::SetUp() {}

void ResizeHmfsSingleTest::TearDown()
{
    system("rm -rf /data/local/Fs* /data/local/HM*");
}

/*
 * @tc.name: ResizeHmfsSingleTest_V_001
 * @tc.desc: test for resize hmfs.
 * @tc.type: FUNC
 */
HWTEST_F(ResizeHmfsSingleTest, ResizeHmfsSingleTest_V_001, TestSize.Level1)
{
    std::cout << "ResizeHmfsSingleTest_V_001 BEGIN" << std::endl;
    std::vector<std::string> params;
    params.push_back("/system/bin/resize.hmfs");
    params.push_back("-V");

    std::string outputFile = "/data/local/test_output.txt";
    ASSERT_EQ(0, ExecutableCmdWithOutput(params, outputFile));
    std::string output = ReadFile(outputFile);
    ASSERT_TRUE(output.find("Hmfstool version") != std::string::npos);
    std::cout << "ResizeHmfsSingleTest_V_001 END" << std::endl;
}

/*
 * @tc.name: ResizeHmfsSingleTest_C_001
 * @tc.desc: test for resize hmfs.
 * @tc.type: FUNC
 */
HWTEST_F(ResizeHmfsSingleTest, ResizeHmfsSingleTest_C_001, TestSize.Level1)
{
    std::cout << "ResizeHmfsSingleTest_C_001 BEGIN" << std::endl;
    std::string device = F2FS_DEVICE;
    ExecutableDdCmd(device, 100);
    ASSERT_EQ(0, ExecMkfsBinary(F2FS_TYPE, device));
    std::string hmDevice = HMFS_DEVICE;
    ExecutableDdCmd(hmDevice, 100);
    ASSERT_EQ(0, ExecMkfsBinary(HMFS_TYPE, hmDevice));

    // mkfs fsck check
    std::string F2fsMkfsFsckOutFileName = "/data/local/Fsck_F2fs_Mkfs_SingleParams_C_001.txt";
    int32_t fsckMkfsF2fsRes = ExecFsckWithOutput(device, F2fsMkfsFsckOutFileName);
    std::string HmfsMkfsFsckOutFileName = "/data/local/Fsck_Hmfs_Mkfs_SingleParams_C_001.txt";
    int32_t fsckMkfsHmfsRes = ExecFsckWithOutput(hmDevice, HmfsMkfsFsckOutFileName);
    ASSERT_EQ(fsckMkfsF2fsRes, fsckMkfsHmfsRes);
    ASSERT_TRUE(PrintFsckErrorMsg(HmfsMkfsFsckOutFileName, hmDevice));
    if (fsckMkfsHmfsRes == 0) {
        ASSERT_EQ(0, RemoveFile(HmfsMkfsFsckOutFileName));
        ASSERT_EQ(0, RemoveFile(F2fsMkfsFsckOutFileName));
    }

    // resize
    std::vector<std::string> params;
    params.clear();
    params.push_back("-C");
    params.push_back("utf8");
    uint64_t f2fsRunTime = 0;
    uint64_t hmfsRunTime = 0;
    ASSERT_EQ(0, ExecResizeBinary(F2FS_TYPE, params, device, f2fsRunTime));
    std::cout << "----------------------------------------------------------------F2FS" << std::endl;
    PrintSuperBlockAndCheckPointData(device);

    ASSERT_EQ(0, ExecResizeBinary(HMFS_TYPE, params, hmDevice, hmfsRunTime));
    std::cout << "----------------------------------------------------------------HMFS" << std::endl;
    PrintSuperBlockAndCheckPointData(hmDevice);

    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(device, f2fsSuperBlock);
    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(hmDevice, hmfsSuperBlock);
    ASSERT_EQ(f2fsSuperBlock->encoding, hmfsSuperBlock->encoding);
    ASSERT_EQ(f2fsSuperBlock->encodingFlags, hmfsSuperBlock->encodingFlags);
    ASSERT_EQ(f2fsSuperBlock->features, hmfsSuperBlock->features);

    ASSERT_EQ(f2fsSuperBlock->encoding, HMFS_ENC_UTF8_12_1);
    ASSERT_TRUE(f2fsSuperBlock->features & HMFS_FEATURE_CASEFOLD);
    ASSERT_EQ(hmfsSuperBlock->encoding, HMFS_ENC_UTF8_12_1);
    ASSERT_TRUE(hmfsSuperBlock->features & HMFS_FEATURE_CASEFOLD);

    // resize fsck check
    std::string HmfsFsckOutFileName = "/data/local/Fsck_Hmfs_SingleParams_C_001.txt";
    std::string F2fsFsckOutFileName = "/data/local/Fsck_F2fs_SingleParams_C_001.txt";
    int32_t fsckF2fsRes = ExecFsckWithOutput(device, F2fsFsckOutFileName);
    int32_t fsckHmfsRes = ExecFsckWithOutput(hmDevice, HmfsFsckOutFileName);
    ASSERT_EQ(fsckF2fsRes, fsckHmfsRes);
    ASSERT_TRUE(PrintFsckErrorMsg(HmfsFsckOutFileName, hmDevice));
    if (fsckHmfsRes == 0) {
        ASSERT_EQ(0, RemoveFile(HmfsFsckOutFileName));
        ASSERT_EQ(0, RemoveFile(F2fsFsckOutFileName));
    }
    ASSERT_EQ(FsBinaryCompare(device, hmDevice, false), 0);
    ASSERT_EQ(FsResultCompare(device, hmDevice), 0);
    (void)CompareRunTime(f2fsRunTime, hmfsRunTime);
    std::cout << "ResizeHmfsSingleTest_C_001 END" << std::endl;
}

/*
 * @tc.name: ResizeHmfs_Abnormal_C_002
 * @tc.desc: test for resize hmfs.
 * @tc.type: FUNC
 */
HWTEST_F(ResizeHmfsSingleTest, ResizeHmfs_Abnormal_C_002, TestSize.Level1)
{
    std::cout << "ResizeHmfs_Abnormal_C_002 BEGIN" << std::endl;
    std::string hmdevice = HMFS_TYPE;
    ExecutableDdCmd(hmdevice, 100);
    ASSERT_EQ(0, ExecMkfsBinary(HMFS_TYPE, hmdevice));
    std::vector<std::string> params;
    params.clear();
    params.push_back("-C");
    params.push_back("error_encoding");

    std::string outputFile = "/data/local/test_output.txt";
    ASSERT_EQ(0, ExecResizeBinaryWithOutput(HMFS_TYPE, params, hmdevice, outputFile));
    std::string output = ReadFile(outputFile);
    ASSERT_TRUE(output.find("Error: Unknown encoding : error_encoding") != std::string::npos);

    std::cout << "----------------------------------------------------------------HMFS" << std::endl;
    PrintSuperBlockAndCheckPointData(hmdevice);

    std::cout << "ResizeHmfs_Abnormal_C_002 END" << std::endl;
}

/*
 * @tc.name: ResizeHmfsSingleTest_O_001
 * @tc.desc: test for resize hmfs.
 * @tc.type: FUNC
 */
HWTEST_F(ResizeHmfsSingleTest, ResizeHmfsSingleTest_O_001, TestSize.Level1)
{
    std::cout << "ResizeHmfsSingleTest_O_001 BEGIN" << std::endl;
    std::string device = F2FS_DEVICE;
    ExecutableDdCmd(device, 100);
    ASSERT_EQ(0, ExecMkfsBinary(F2FS_TYPE, device));
    std::string hmDevice = HMFS_DEVICE;
    ExecutableDdCmd(hmDevice, 100);
    ASSERT_EQ(0, ExecMkfsBinary(HMFS_TYPE, hmDevice));

    // mkfs fsck check
    std::string F2fsMkfsFsckOutFileName = "/data/local/Fsck_F2fs_Mkfs_SingleParams_O_001.txt";
    int32_t fsckMkfsF2fsRes = ExecFsckWithOutput(device, F2fsMkfsFsckOutFileName);
    std::string HmfsMkfsFsckOutFileName = "/data/local/Fsck_Hmfs_Mkfs_SingleParams_O_001.txt";
    int32_t fsckMkfsHmfsRes = ExecFsckWithOutput(hmDevice, HmfsMkfsFsckOutFileName);
    ASSERT_EQ(fsckMkfsF2fsRes, fsckMkfsHmfsRes);
    ASSERT_TRUE(PrintFsckErrorMsg(HmfsMkfsFsckOutFileName, hmDevice));
    if (fsckMkfsHmfsRes == 0) {
        ASSERT_EQ(0, RemoveFile(HmfsMkfsFsckOutFileName));
        ASSERT_EQ(0, RemoveFile(F2fsMkfsFsckOutFileName));
    }

    // resize
    std::vector<std::string> params;
    params.clear();
    params.push_back("-O");
    params.push_back("extra_attr,project_quota");
    uint64_t f2fsRunTime = 0;
    uint64_t hmfsRunTime = 0;
    ASSERT_EQ(0, ExecResizeBinary(F2FS_TYPE, params, device, f2fsRunTime));
    std::cout << "----------------------------------------------------------------F2FS" << std::endl;
    PrintSuperBlockAndCheckPointData(device);
    ASSERT_EQ(0, ExecResizeBinary(HMFS_TYPE, params, hmDevice, hmfsRunTime));
    std::cout << "----------------------------------------------------------------HMFS" << std::endl;
    PrintSuperBlockAndCheckPointData(hmDevice);

    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(device, f2fsSuperBlock);
    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(hmDevice, hmfsSuperBlock);
    ASSERT_EQ(f2fsSuperBlock->features, hmfsSuperBlock->features);

    ASSERT_TRUE(f2fsSuperBlock->features & HMFS_FEATURE_EXTRA_ATTR);
    ASSERT_TRUE(f2fsSuperBlock->features & HMFS_FEATURE_PRJQUOTA);
    ASSERT_TRUE(hmfsSuperBlock->features & HMFS_FEATURE_EXTRA_ATTR);
    ASSERT_TRUE(hmfsSuperBlock->features & HMFS_FEATURE_PRJQUOTA);

    // resize fsck check
    std::string HmfsFsckOutFileName = "/data/local/Fsck_Hmfs_SingleParams_O_001.txt";
    std::string F2fsFsckOutFileName = "/data/local/Fsck_F2fs_SingleParams_O_001.txt";
    int32_t fsckF2fsRes = ExecFsckWithOutput(device, F2fsFsckOutFileName);
    int32_t fsckHmfsRes = ExecFsckWithOutput(hmDevice, HmfsFsckOutFileName);
    ASSERT_EQ(fsckF2fsRes, fsckHmfsRes);
    ASSERT_TRUE(PrintFsckErrorMsg(HmfsFsckOutFileName, hmDevice));
    if (fsckHmfsRes == 0) {
        ASSERT_EQ(0, RemoveFile(HmfsFsckOutFileName));
        ASSERT_EQ(0, RemoveFile(F2fsFsckOutFileName));
    }
    ASSERT_EQ(FsBinaryCompare(device, hmDevice, false), 0);
    ASSERT_EQ(FsResultCompare(device, hmDevice), 0);
    (void)CompareRunTime(f2fsRunTime, hmfsRunTime);
    std::cout << "ResizeHmfsSingleTest_O_001 END" << std::endl;
}

/*
 * @tc.name: ResizeHmfsSingleTest_O_002
 * @tc.desc: test for resize hmfs.
 * @tc.type: FUNC
 */
HWTEST_F(ResizeHmfsSingleTest, ResizeHmfsSingleTest_O_002, TestSize.Level1)
{
    std::cout << "ResizeHmfsSingleTest_O_002 BEGIN" << std::endl;
    std::string device = F2FS_DEVICE;
    ExecutableDdCmd(device, 100);
    ASSERT_EQ(0, ExecMkfsBinary(F2FS_TYPE, device));
    std::string hmDevice = HMFS_DEVICE;
    ExecutableDdCmd(hmDevice, 100);
    ASSERT_EQ(0, ExecMkfsBinary(HMFS_TYPE, hmDevice));

    // mkfs fsck check
    std::string F2fsMkfsFsckOutFileName = "/data/local/Fsck_F2fs_Mkfs_SingleParams_O_002.txt";
    int32_t fsckMkfsF2fsRes = ExecFsckWithOutput(device, F2fsMkfsFsckOutFileName);
    std::string HmfsMkfsFsckOutFileName = "/data/local/Fsck_Hmfs_Mkfs_SingleParams_O_002.txt";
    int32_t fsckMkfsHmfsRes = ExecFsckWithOutput(hmDevice, HmfsMkfsFsckOutFileName);
    ASSERT_EQ(fsckMkfsF2fsRes, fsckMkfsHmfsRes);
    ASSERT_TRUE(PrintFsckErrorMsg(HmfsMkfsFsckOutFileName, hmDevice));
    if (fsckMkfsHmfsRes == 0) {
        ASSERT_EQ(0, RemoveFile(HmfsMkfsFsckOutFileName));
        ASSERT_EQ(0, RemoveFile(F2fsMkfsFsckOutFileName));
    }

    // resize
    std::vector<std::string> params;
    params.clear();
    params.push_back("-O");
    params.push_back("casefold");
    params.push_back("-C");
    params.push_back("utf8");
    uint64_t f2fsRunTime = 0;
    uint64_t hmfsRunTime = 0;
    ASSERT_EQ(0, ExecResizeBinary(F2FS_TYPE, params, device, f2fsRunTime));
    std::cout << "----------------------------------------------------------------F2FS" << std::endl;
    PrintSuperBlockAndCheckPointData(device);
    ASSERT_EQ(0, ExecResizeBinary(HMFS_TYPE, params, hmDevice, hmfsRunTime));
    std::cout << "----------------------------------------------------------------HMFS" << std::endl;
    PrintSuperBlockAndCheckPointData(hmDevice);

    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(device, f2fsSuperBlock);
    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(hmDevice, hmfsSuperBlock);
    ASSERT_EQ(f2fsSuperBlock->features, hmfsSuperBlock->features);
    ASSERT_EQ(f2fsSuperBlock->encoding, hmfsSuperBlock->encoding);
    ASSERT_EQ(f2fsSuperBlock->encodingFlags, hmfsSuperBlock->encodingFlags);

    ASSERT_EQ(f2fsSuperBlock->encoding, HMFS_ENC_UTF8_12_1);
    ASSERT_TRUE(f2fsSuperBlock->features & HMFS_FEATURE_CASEFOLD);
    ASSERT_EQ(hmfsSuperBlock->encoding, HMFS_ENC_UTF8_12_1);
    ASSERT_TRUE(hmfsSuperBlock->features & HMFS_FEATURE_CASEFOLD);

    // resize fsck check
    std::string HmfsFsckOutFileName = "/data/local/Fsck_Hmfs_SingleParams_O_002.txt";
    std::string F2fsFsckOutFileName = "/data/local/Fsck_F2fs_SingleParams_O_002.txt";
    int32_t fsckF2fsRes = ExecFsckWithOutput(device, F2fsFsckOutFileName);
    int32_t fsckHmfsRes = ExecFsckWithOutput(hmDevice, HmfsFsckOutFileName);
    ASSERT_EQ(fsckF2fsRes, fsckHmfsRes);
    ASSERT_TRUE(PrintFsckErrorMsg(HmfsFsckOutFileName, hmDevice));
    if (fsckHmfsRes == 0) {
        ASSERT_EQ(0, RemoveFile(HmfsFsckOutFileName));
        ASSERT_EQ(0, RemoveFile(F2fsFsckOutFileName));
    }
    ASSERT_EQ(FsBinaryCompare(device, hmDevice, false), 0);
    ASSERT_EQ(FsResultCompare(device, hmDevice), 0);
    (void)CompareRunTime(f2fsRunTime, hmfsRunTime);
    std::cout << "ResizeHmfsSingleTest_O_002 END" << std::endl;
}

/*
 * @tc.name: ResizeHmfsSingleTest_O_003
 * @tc.desc: test for resize hmfs.
 * @tc.type: FUNC
 */
HWTEST_F(ResizeHmfsSingleTest, ResizeHmfsSingleTest_O_003, TestSize.Level1)
{
    std::cout << "ResizeHmfsSingleTest_O_003 BEGIN" << std::endl;
    std::string device = F2FS_DEVICE;
    ExecutableDdCmd(device, 100);
    ASSERT_EQ(0, ExecMkfsBinary(F2FS_TYPE, device));
    std::string hmDevice = HMFS_DEVICE;
    ExecutableDdCmd(hmDevice, 100);
    ASSERT_EQ(0, ExecMkfsBinary(HMFS_TYPE, hmDevice));

    // mkfs fsck check
    std::string F2fsMkfsFsckOutFileName = "/data/local/Fsck_F2fs_Mkfs_SingleParams_O_003.txt";
    int32_t fsckMkfsF2fsRes = ExecFsckWithOutput(device, F2fsMkfsFsckOutFileName);
    std::string HmfsMkfsFsckOutFileName = "/data/local/Fsck_Hmfs_Mkfs_SingleParams_O_003.txt";
    int32_t fsckMkfsHmfsRes = ExecFsckWithOutput(hmDevice, HmfsMkfsFsckOutFileName);
    ASSERT_EQ(fsckMkfsF2fsRes, fsckMkfsHmfsRes);
    ASSERT_TRUE(PrintFsckErrorMsg(HmfsMkfsFsckOutFileName, hmDevice));
    if (fsckMkfsHmfsRes == 0) {
        ASSERT_EQ(0, RemoveFile(HmfsMkfsFsckOutFileName));
        ASSERT_EQ(0, RemoveFile(F2fsMkfsFsckOutFileName));
    }

    // resize
    std::vector<std::string> params;
    params.clear();
    params.push_back("-O");
    params.push_back("casefold,extra_attr,project_quota");
    params.push_back("-C");
    params.push_back("utf8");
    uint64_t f2fsRunTime = 0;
    uint64_t hmfsRunTime = 0;
    ASSERT_EQ(0, ExecResizeBinary(F2FS_TYPE, params, device, f2fsRunTime));
    std::cout << "----------------------------------------------------------------F2FS" << std::endl;
    PrintSuperBlockAndCheckPointData(device);
    ASSERT_EQ(0, ExecResizeBinary(HMFS_TYPE, params, hmDevice, hmfsRunTime));
    std::cout << "----------------------------------------------------------------HMFS" << std::endl;
    PrintSuperBlockAndCheckPointData(hmDevice);

    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(device, f2fsSuperBlock);
    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(hmDevice, hmfsSuperBlock);
    ASSERT_EQ(f2fsSuperBlock->features, hmfsSuperBlock->features);
    ASSERT_EQ(f2fsSuperBlock->encoding, hmfsSuperBlock->encoding);
    ASSERT_EQ(f2fsSuperBlock->encodingFlags, hmfsSuperBlock->encodingFlags);

    ASSERT_EQ(hmfsSuperBlock->encoding, HMFS_ENC_UTF8_12_1);
    ASSERT_TRUE(hmfsSuperBlock->features & HMFS_FEATURE_CASEFOLD);
    ASSERT_TRUE(hmfsSuperBlock->features & HMFS_FEATURE_EXTRA_ATTR);
    ASSERT_TRUE(hmfsSuperBlock->features & HMFS_FEATURE_PRJQUOTA);

    // resize fsck check
    std::string HmfsFsckOutFileName = "/data/local/Fsck_Hmfs_SingleParams_O_001.txt";
    std::string F2fsFsckOutFileName = "/data/local/Fsck_F2fs_SingleParams_O_001.txt";
    int32_t fsckF2fsRes = ExecFsckWithOutput(device, F2fsFsckOutFileName);
    int32_t fsckHmfsRes = ExecFsckWithOutput(hmDevice, HmfsFsckOutFileName);
    ASSERT_EQ(fsckF2fsRes, fsckHmfsRes);
    ASSERT_TRUE(PrintFsckErrorMsg(HmfsFsckOutFileName, hmDevice));
    if (fsckHmfsRes == 0) {
        ASSERT_EQ(0, RemoveFile(HmfsFsckOutFileName));
        ASSERT_EQ(0, RemoveFile(F2fsFsckOutFileName));
    }
    ASSERT_EQ(FsBinaryCompare(device, hmDevice, false), 0);
    ASSERT_EQ(FsResultCompare(device, hmDevice), 0);
    (void)CompareRunTime(f2fsRunTime, hmfsRunTime);
    std::cout << "ResizeHmfsSingleTest_O_003 END" << std::endl;
}

/*
 * @tc.name: ResizeHmfs_Abnormal_O_004
 * @tc.desc: test for resize hmfs.
 * @tc.type: FUNC
 */
HWTEST_F(ResizeHmfsSingleTest, ResizeHmfs_Abnormal_O_004, TestSize.Level1)
{
    std::cout << "ResizeHmfs_Abnormal_O_004 BEGIN" << std::endl;
    std::string device = HMFS_DEVICE;
    ExecutableDdCmd(device, 100);
    ASSERT_EQ(0, ExecMkfsBinary(HMFS_TYPE, device));
    std::vector<std::string> params;
    params.clear();
    params.push_back("-O");
    params.push_back("abcd");

    std::string outputFile = "/data/local/test_output_ResizeHmfs_Abnormal_O_004.txt";
    ASSERT_NE(0, ExecResizeBinaryWithOutput(HMFS_TYPE, params, device, outputFile));
    std::string output = ReadFile(outputFile);
    ASSERT_TRUE(output.find("Error: Wrong features") != std::string::npos);
    std::cout << "----------------------------------------------------------------HMFS" << std::endl;
    PrintSuperBlockAndCheckPointData(device);

    ASSERT_EQ(0, RemoveFile(outputFile));
    std::cout << "ResizeHmfs_Abnormal_O_004 END" << std::endl;
}

/*
 * @tc.name: ResizeHmfs_Abnormal_s_001
 * @tc.desc: test for resize hmfs.
 * @tc.type: FUNC
 */
HWTEST_F(ResizeHmfsSingleTest, ResizeHmfs_Abnormal_s_001, TestSize.Level1)
{
    std::cout << "ResizeHmfs_Abnormal_s_001 BEGIN" << std::endl;
    std::string device = F2FS_DEVICE;
    ExecutableDdCmd(device, 100);
    ASSERT_EQ(0, ExecMkfsBinary(HMFS_TYPE, device));

    std::vector<std::string> params;
    params.clear();
    params.push_back("-t");
    params.push_back("102400");
    std::string outputFile = "/data/local/test_output.txt";
    ASSERT_EQ(0, ExecResizeBinaryWithOutput(HMFS_TYPE, params, device, outputFile));
    std::string output = ReadFile(outputFile);
    ASSERT_TRUE(output.find("Nothing to resize, now only supports resizing with safe resize flag") != std::string::npos);

    std::cout << "----------------------------------------------------------------HMFS" << std::endl;
    PrintSuperBlockAndCheckPointData(device);
    ASSERT_EQ(0, RemoveFile(outputFile));
    std::cout << "ResizeHmfs_Abnormal_s_001 END" << std::endl;
}

/*
 * @tc.name: ResizeHmfsSingleTest_t_001
 * @tc.desc: test for resize hmfs.
 * @tc.type: FUNC
 */
HWTEST_F(ResizeHmfsSingleTest, ResizeHmfsSingleTest_t_001, TestSize.Level1)
{
    std::cout << "ResizeHmfsSingleTest_t_001 BEGIN" << std::endl;
    std::string device = F2FS_DEVICE;
    ExecutableDdCmd(device, 100);
    ASSERT_EQ(0, ExecMkfsBinary(F2FS_TYPE, device));

    std::string hmDevice = HMFS_DEVICE;
    ExecutableDdCmd(hmDevice, 100);
    ASSERT_EQ(0, ExecMkfsBinary(HMFS_TYPE, hmDevice));

    // mkfs fsck check
    std::string F2fsMkfsFsckOutFileName = "/data/local/Fsck_F2fs_Mkfs_SingleParams_t_001.txt";
    int32_t fsckMkfsF2fsRes = ExecFsckWithOutput(device, F2fsMkfsFsckOutFileName);
    std::string HmfsMkfsFsckOutFileName = "/data/local/Fsck_Hmfs_Mkfs_SingleParams_t_001.txt";
    int32_t fsckMkfsHmfsRes = ExecFsckWithOutput(hmDevice, HmfsMkfsFsckOutFileName);
    ASSERT_EQ(fsckMkfsF2fsRes, fsckMkfsHmfsRes);
    ASSERT_TRUE(PrintFsckErrorMsg(HmfsMkfsFsckOutFileName, hmDevice));
    if (fsckMkfsHmfsRes == 0) {
        ASSERT_EQ(0, RemoveFile(HmfsMkfsFsckOutFileName));
        ASSERT_EQ(0, RemoveFile(F2fsMkfsFsckOutFileName));
    }

    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(device, f2fsSuperBlock);
    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(hmDevice, hmfsSuperBlock);
    ASSERT_EQ(f2fsSuperBlock->blockCount, hmfsSuperBlock->blockCount);

    // resize
    uint64_t targetSectors = 102400;
    std::vector<std::string> params;
    params.clear();
    params.push_back("-s");
    params.push_back("-t");
    params.push_back(std::to_string(targetSectors));
    uint64_t f2fsRunTime = 0;
    uint64_t hmfsRunTime = 0;
    ASSERT_EQ(0, ExecResizeBinary(F2FS_TYPE, params, device, f2fsRunTime));
    std::cout << "----------------------------------------------------------------F2FS" << std::endl;
    PrintSuperBlockAndCheckPointData(device);
    ASSERT_EQ(0, ExecResizeBinary(HMFS_TYPE, params, hmDevice, hmfsRunTime));
    std::cout << "----------------------------------------------------------------HMFS" << std::endl;
    PrintSuperBlockAndCheckPointData(hmDevice);

    auto resizeF2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(device, resizeF2fsSuperBlock);
    auto resizeHmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(hmDevice, resizeHmfsSuperBlock);
    ASSERT_EQ(resizeF2fsSuperBlock->blockCount, resizeHmfsSuperBlock->blockCount);
    ASSERT_EQ(hmfsSuperBlock->blockCount, resizeHmfsSuperBlock->blockCount*2);

    // 值校验
    uint64_t targetBlockCounts = targetSectors >> resizeF2fsSuperBlock->log2SectorsPerBlock;
    ASSERT_EQ(targetBlockCounts, resizeF2fsSuperBlock->blockCount);

    // resize fsck check
    std::string HmfsFsckOutFileName = "/data/local/Fsck_Hmfs_SingleParams_t_001.txt";
    std::string F2fsFsckOutFileName = "/data/local/Fsck_F2fs_SingleParams_t_001.txt";
    int32_t fsckF2fsRes = ExecFsckWithOutput(device, F2fsFsckOutFileName);
    int32_t fsckHmfsRes = ExecFsckWithOutput(hmDevice, HmfsFsckOutFileName);
    ASSERT_EQ(fsckF2fsRes, fsckHmfsRes);
    ASSERT_TRUE(PrintFsckErrorMsg(HmfsFsckOutFileName, hmDevice));
    if (fsckHmfsRes == 0) {
        ASSERT_EQ(0, RemoveFile(HmfsFsckOutFileName));
        ASSERT_EQ(0, RemoveFile(F2fsFsckOutFileName));
    }
    ASSERT_EQ(FsBinaryCompare(device, hmDevice), 0);
    ASSERT_EQ(FsResultCompare(device, hmDevice), 0);
    (void)CompareRunTime(f2fsRunTime, hmfsRunTime);
    std::cout << "ResizeHmfsSingleTest_t_001 END" << std::endl;
}

/*
 * @tc.name: ResizeHmfsSingleTest_t_002
 * @tc.desc: test for resize hmfs.
 * @tc.type: FUNC
 */
HWTEST_F(ResizeHmfsSingleTest, ResizeHmfsSingleTest_t_002, TestSize.Level1)
{
    std::cout << "ResizeHmfsSingleTest_t_002 BEGIN" << std::endl;
    std::string device = F2FS_DEVICE;
    ExecutableDdCmd(device, 100);
    ASSERT_EQ(0, ExecMkfsBinary(F2FS_TYPE, device));
    std::string hmDevice = HMFS_DEVICE;
    ExecutableDdCmd(hmDevice, 100);
    ASSERT_EQ(0, ExecMkfsBinary(HMFS_TYPE, hmDevice));

    // mkfs fsck check
    std::string F2fsMkfsFsckOutFileName = "/data/local/Fsck_F2fs_Mkfs_SingleParams_t_002.txt";
    int32_t fsckMkfsF2fsRes = ExecFsckWithOutput(device, F2fsMkfsFsckOutFileName);
    std::string HmfsMkfsFsckOutFileName = "/data/local/Fsck_Hmfs_Mkfs_SingleParams_t_002.txt";
    int32_t fsckMkfsHmfsRes = ExecFsckWithOutput(hmDevice, HmfsMkfsFsckOutFileName);
    ASSERT_EQ(fsckMkfsF2fsRes, fsckMkfsHmfsRes);
    ASSERT_TRUE(PrintFsckErrorMsg(HmfsMkfsFsckOutFileName, hmDevice));
    if (fsckMkfsHmfsRes == 0) {
        ASSERT_EQ(0, RemoveFile(HmfsMkfsFsckOutFileName));
        ASSERT_EQ(0, RemoveFile(F2fsMkfsFsckOutFileName));
    }

    // resize shrink
    uint64_t targetSectors = 122880;
    std::vector<std::string> params;
    params.clear();
    params.push_back("-s");
    params.push_back("-t");
    params.push_back(std::to_string(targetSectors));
    uint64_t f2fsRunTime = 0;
    uint64_t hmfsRunTime = 0;
    ASSERT_EQ(0, ExecResizeBinary(F2FS_TYPE, params, device, f2fsRunTime));
    std::cout << "----------------------------------------------------------------F2FS" << std::endl;
    PrintSuperBlockAndCheckPointData(device);
    ASSERT_EQ(0, ExecResizeBinary(HMFS_TYPE, params, hmDevice, hmfsRunTime));
    std::cout << "----------------------------------------------------------------HMFS" << std::endl;
    PrintSuperBlockAndCheckPointData(hmDevice);

    // 值校验
    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(device, f2fsSuperBlock);
    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(hmDevice, hmfsSuperBlock);
    ASSERT_EQ(f2fsSuperBlock->blockCount, hmfsSuperBlock->blockCount);
    uint64_t targetBlockCounts = targetSectors >> f2fsSuperBlock->log2SectorsPerBlock;
    ASSERT_EQ(targetBlockCounts, f2fsSuperBlock->blockCount);

    // resize grow
    targetSectors = 184320;
    std::vector<std::string> resizeParams;
    resizeParams.clear();
    resizeParams.push_back("-t");
    resizeParams.push_back(std::to_string(targetSectors));
    ASSERT_EQ(0, ExecResizeBinary(F2FS_TYPE, resizeParams, device));
    std::cout << "----------------------------------------------------------------F2FS" << std::endl;
    PrintSuperBlockAndCheckPointData(device);
    ASSERT_EQ(0, ExecResizeBinary(HMFS_TYPE, resizeParams, hmDevice));
    std::cout << "----------------------------------------------------------------HMFS" << std::endl;
    PrintSuperBlockAndCheckPointData(hmDevice);

    // 值校验
    auto resizeF2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(device, resizeF2fsSuperBlock);
    auto resizeHmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(hmDevice, resizeHmfsSuperBlock);
    ASSERT_EQ(resizeF2fsSuperBlock->blockCount, resizeHmfsSuperBlock->blockCount);
    targetBlockCounts = targetSectors >> resizeF2fsSuperBlock->log2SectorsPerBlock;
    ASSERT_EQ(targetBlockCounts, resizeF2fsSuperBlock->blockCount);

    //fsck check
    std::string HmfsFsckOutFileName = "/data/local/Fsck_Hmfs_SingleParams_t_002.txt";
    std::string F2fsFsckOutFileName = "/data/local/Fsck_F2fs_SingleParams_t_002.txt";
    int32_t fsckF2fsRes = ExecFsckWithOutput(device, F2fsFsckOutFileName);
    int32_t fsckHmfsRes = ExecFsckWithOutput(hmDevice, HmfsFsckOutFileName);
    ASSERT_EQ(fsckF2fsRes, fsckHmfsRes);
    ASSERT_TRUE(PrintFsckErrorMsg(HmfsFsckOutFileName, hmDevice));
    if (fsckHmfsRes == 0) {
        ASSERT_EQ(0, RemoveFile(HmfsFsckOutFileName));
        ASSERT_EQ(0, RemoveFile(F2fsFsckOutFileName));
    }
    ASSERT_EQ(FsBinaryCompare(device, hmDevice), 0);
    ASSERT_EQ(FsResultCompare(device, hmDevice), 0);
    (void)CompareRunTime(f2fsRunTime, hmfsRunTime);
    std::cout << "ResizeHmfsSingleTest_t_002 END" << std::endl;
}

/*
 * @tc.name: ResizeHmfs_Abnormal_t_003
 * @tc.desc: test for resize hmfs.
 * @tc.type: FUNC
 */
HWTEST_F(ResizeHmfsSingleTest, ResizeHmfs_Abnormal_t_003, TestSize.Level1)
{
    std::cout << "ResizeHmfs_Abnormal_t_003 BEGIN" << std::endl;
    std::string device = F2FS_DEVICE;
    ExecutableDdCmd(device, 100);
    ASSERT_EQ(0, ExecMkfsBinary(F2FS_TYPE, device));
    std::string hmDevice = HMFS_DEVICE;
    ExecutableDdCmd(hmDevice, 100);
    ASSERT_EQ(0, ExecMkfsBinary(HMFS_TYPE, hmDevice));

    // mkfs fsck check
    std::string F2fsMkfsFsckOutFileName = "/data/local/Fsck_F2fs_Mkfs_ResizeHmfs_Abnormal_t_003.txt";
    int32_t fsckMkfsF2fsRes = ExecFsckWithOutput(device, F2fsMkfsFsckOutFileName);
    std::string HmfsMkfsFsckOutFileName = "/data/local/Fsck_Hmfs_Mkfs_ResizeHmfs_Abnormal_t_003.txt";
    int32_t fsckMkfsHmfsRes = ExecFsckWithOutput(hmDevice, HmfsMkfsFsckOutFileName);
    ASSERT_EQ(fsckMkfsF2fsRes, fsckMkfsHmfsRes);
    ASSERT_TRUE(PrintFsckErrorMsg(HmfsMkfsFsckOutFileName, hmDevice));
    if (fsckMkfsHmfsRes == 0) {
        ASSERT_EQ(0, RemoveFile(HmfsMkfsFsckOutFileName));
        ASSERT_EQ(0, RemoveFile(F2fsMkfsFsckOutFileName));
    }

    // resize shrink
    std::vector<std::string> params;
    params.clear();
    params.push_back("-s");
    params.push_back("-t");
    params.push_back("102400");
    uint64_t f2fsRunTime = 0;
    uint64_t hmfsRunTime = 0;
    ASSERT_EQ(0, ExecResizeBinary(F2FS_TYPE, params, device, f2fsRunTime));
    std::cout << "----------------------------------------------------------------F2FS" << std::endl;
    PrintSuperBlockAndCheckPointData(device);
    ASSERT_EQ(0, ExecResizeBinary(HMFS_TYPE, params, hmDevice, hmfsRunTime));
    std::cout << "----------------------------------------------------------------HMFS" << std::endl;
    PrintSuperBlockAndCheckPointData(hmDevice);

    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(hmDevice, hmfsSuperBlock);
    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(device, f2fsSuperBlock);
    ASSERT_EQ(f2fsSuperBlock->blockCount, hmfsSuperBlock->blockCount);

    // resize grow
    std::vector<std::string> resizeParams;
    resizeParams.clear();
    ASSERT_NE(0, ExecResizeBinary(F2FS_TYPE, resizeParams, device));
    ASSERT_NE(0, ExecResizeBinary(HMFS_TYPE, resizeParams, hmDevice));

    //fsck check
    std::string HmfsFsckOutFileName = "/data/local/Fsck_Hmfs_SingleParams_t_003.txt";
    std::string F2fsFsckOutFileName = "/data/local/Fsck_F2fs_SingleParams_t_003.txt";
    int32_t fsckF2fsRes = ExecFsckWithOutput(device, F2fsFsckOutFileName);
    int32_t fsckHmfsRes = ExecFsckWithOutput(hmDevice, HmfsFsckOutFileName);
    ASSERT_EQ(fsckF2fsRes, fsckHmfsRes);
    ASSERT_TRUE(PrintFsckErrorMsg(HmfsFsckOutFileName, hmDevice));
    if (fsckHmfsRes == 0) {
        ASSERT_EQ(0, RemoveFile(HmfsFsckOutFileName));
        ASSERT_EQ(0, RemoveFile(F2fsFsckOutFileName));
    }
    ASSERT_EQ(FsBinaryCompare(device, hmDevice), 0);
    ASSERT_EQ(FsResultCompare(device, hmDevice), 0);
    (void)CompareRunTime(f2fsRunTime, hmfsRunTime);
    std::cout << "ResizeHmfs_Abnormal_t_003 END" << std::endl;
}

/*
 * @tc.name: ResizeHmfsSingleTest_t_004
 * @tc.desc: test for resize hmfs.
 * @tc.type: FUNC
 */
HWTEST_F(ResizeHmfsSingleTest, ResizeHmfsSingleTest_t_004, TestSize.Level1)
{
    std::cout << "ResizeHmfsSingleTest_t_004 BEGIN" << std::endl;
    std::string device = F2FS_DEVICE;
    ExecutableDdCmd(device, 1000);
    ASSERT_EQ(0, ExecMkfsBinary(F2FS_TYPE, device));

    std::string hmDevice = HMFS_DEVICE;
    ExecutableDdCmd(hmDevice, 1000);
    ASSERT_EQ(0, ExecMkfsBinary(HMFS_TYPE, hmDevice));

    // mkfs fsck check
    std::string F2fsMkfsFsckOutFileName = "/data/local/Fsck_F2fs_Mkfs_SingleParams_t_004.txt";
    int32_t fsckMkfsF2fsRes = ExecFsckWithOutput(device, F2fsMkfsFsckOutFileName);
    std::string HmfsMkfsFsckOutFileName = "/data/local/Fsck_Hmfs_Mkfs_SingleParams_t_004.txt";
    int32_t fsckMkfsHmfsRes = ExecFsckWithOutput(hmDevice, HmfsMkfsFsckOutFileName);
    ASSERT_EQ(fsckMkfsF2fsRes, fsckMkfsHmfsRes);
    ASSERT_TRUE(PrintFsckErrorMsg(HmfsMkfsFsckOutFileName, hmDevice));
    if (fsckMkfsHmfsRes == 0) {
        ASSERT_EQ(0, RemoveFile(HmfsMkfsFsckOutFileName));
        ASSERT_EQ(0, RemoveFile(F2fsMkfsFsckOutFileName));
    }

    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(device, f2fsSuperBlock);
    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(hmDevice, hmfsSuperBlock);
    ASSERT_EQ(f2fsSuperBlock->blockCount, hmfsSuperBlock->blockCount);

    // resize
    uint64_t targetSectors = 1024000;
    std::vector<std::string> params;
    params.clear();
    params.push_back("-s");
    params.push_back("-t");
    params.push_back(std::to_string(targetSectors));
    uint64_t f2fsRunTime = 0;
    uint64_t hmfsRunTime = 0;
    ASSERT_EQ(0, ExecResizeBinary(F2FS_TYPE, params, device, f2fsRunTime));
    std::cout << "----------------------------------------------------------------F2FS" << std::endl;
    PrintSuperBlockAndCheckPointData(device);
    ASSERT_EQ(0, ExecResizeBinary(HMFS_TYPE, params, hmDevice, hmfsRunTime));
    std::cout << "----------------------------------------------------------------HMFS" << std::endl;
    PrintSuperBlockAndCheckPointData(hmDevice);

    // 值校验
    auto resizeF2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(device, resizeF2fsSuperBlock);
    auto resizeHmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(hmDevice, resizeHmfsSuperBlock);
    ASSERT_EQ(resizeF2fsSuperBlock->blockCount, resizeHmfsSuperBlock->blockCount);
    ASSERT_EQ(hmfsSuperBlock->blockCount, resizeHmfsSuperBlock->blockCount*2);
    uint64_t targetBlockCounts = targetSectors >> resizeF2fsSuperBlock->log2SectorsPerBlock;
    ASSERT_EQ(targetBlockCounts, resizeF2fsSuperBlock->blockCount);

    //fsck check
    std::string HmfsFsckOutFileName = "/data/local/Fsck_Hmfs_SingleParams_t_004.txt";
    std::string F2fsFsckOutFileName = "/data/local/Fsck_F2fs_SingleParams_t_004.txt";
    int32_t fsckF2fsRes = ExecFsckWithOutput(device, F2fsFsckOutFileName);
    int32_t fsckHmfsRes = ExecFsckWithOutput(hmDevice, HmfsFsckOutFileName);
    ASSERT_EQ(fsckF2fsRes, fsckHmfsRes);
    ASSERT_TRUE(PrintFsckErrorMsg(HmfsFsckOutFileName, hmDevice));
    if (fsckHmfsRes == 0) {
        ASSERT_EQ(0, RemoveFile(HmfsFsckOutFileName));
        ASSERT_EQ(0, RemoveFile(F2fsFsckOutFileName));
    }
    ASSERT_EQ(FsBinaryCompare(device, hmDevice), 0);
    ASSERT_EQ(FsResultCompare(device, hmDevice), 0);
    (void)CompareRunTime(f2fsRunTime, hmfsRunTime);
    std::cout << "ResizeHmfsSingleTest_t_004 END" << std::endl;
}

/*
 * @tc.name: ResizeHmfs_Abnormal_t_005
 * @tc.desc: test for resize hmfs.
 * @tc.type: FUNC
 */
HWTEST_F(ResizeHmfsSingleTest, ResizeHmfs_Abnormal_t_005, TestSize.Level1)
{
    std::cout << "ResizeHmfs_Abnormal_t_005 BEGIN" << std::endl;
    std::string device = F2FS_DEVICE;
    ExecutableDdCmd(device, 100);
    ASSERT_EQ(0, ExecMkfsBinary(HMFS_TYPE, device));
    std::string HmfsMkfsFsckOutFileName = "/data/local/Fsck_Hmfs_Mkfs_SingleParams_t_005.txt";
    ASSERT_EQ(0, ExecFsckWithOutput(device, HmfsMkfsFsckOutFileName));
    ASSERT_TRUE(PrintFsckErrorMsg(HmfsMkfsFsckOutFileName, device));
    ASSERT_EQ(0, RemoveFile(HmfsMkfsFsckOutFileName));

    std::vector<std::string> params;
    params.clear();
    params.push_back("-s");
    params.push_back("-t");
    params.push_back("20");
    std::string outputFile = "/data/local/test_output.txt";
    ASSERT_EQ(0, ExecResizeBinaryWithOutput(HMFS_TYPE, params, device, outputFile));

    std::cout << "----------------------------------------------------------------HMFS" << std::endl;
    PrintSuperBlockAndCheckPointData(device);

    std::string output = ReadFile(outputFile);
    ASSERT_TRUE(output.find("Error: Device size is not sufficient for HMFS volume, more segment needed") != std::string::npos);

    ASSERT_EQ(0, RemoveFile(outputFile));
    std::cout << "ResizeHmfs_Abnormal_t_005 END" << std::endl;
}

/*
 * @tc.name: ResizeHmfs_Abnormal_t_006
 * @tc.desc: test for resize hmfs.
 * @tc.type: FUNC
 */
HWTEST_F(ResizeHmfsSingleTest, ResizeHmfs_Abnormal_t_006, TestSize.Level1)
{
    std::cout << "ResizeHmfs_Abnormal_t_006 BEGIN" << std::endl;
    std::string device = F2FS_DEVICE;
    ExecutableDdCmd(device, 100);
    ASSERT_EQ(0, ExecMkfsBinary(HMFS_TYPE, device));
    std::string HmfsMkfsFsckOutFileName = "/data/local/Fsck_Hmfs_Mkfs_SingleParams_t_006.txt";
    ASSERT_EQ(0, ExecFsckWithOutput(device, HmfsMkfsFsckOutFileName));
    ASSERT_TRUE(PrintFsckErrorMsg(HmfsMkfsFsckOutFileName, device));
    ASSERT_EQ(0, RemoveFile(HmfsMkfsFsckOutFileName));

    std::vector<std::string> params;
    params.clear();
    params.push_back("-t");
    params.push_back("409600");
    std::string outputFile = "/data/local/test_output.txt";
    ASSERT_EQ(0, ExecResizeBinaryWithOutput(HMFS_TYPE, params, device, outputFile));
    std::string output = ReadFile(outputFile);
    ASSERT_TRUE(output.find("Out-of-range Target") != std::string::npos);
    ASSERT_EQ(0, RemoveFile(outputFile));
    std::cout << "ResizeHmfs_Abnormal_t_006 END" << std::endl;
}

/*
 * @tc.name: ResizeHmfsSingleTest_o_001
 * @tc.desc: test for resize hmfs.
 * @tc.type: FUNC
 */
HWTEST_F(ResizeHmfsSingleTest, ResizeHmfsSingleTest_o_001, TestSize.Level1)
{
    std::cout << "ResizeHmfsSingleTest_o_001 BEGIN" << std::endl;
    std::string device = F2FS_DEVICE;
    ExecutableDdCmd(device, 100);
    ASSERT_EQ(0, ExecMkfsBinary(F2FS_TYPE, device));
    std::string hmDevice = HMFS_DEVICE;
    ExecutableDdCmd(hmDevice, 100);
    ASSERT_EQ(0, ExecMkfsBinary(HMFS_TYPE, hmDevice));

    // mkfs fsck check
    std::string F2fsMkfsFsckOutFileName = "/data/local/Fsck_F2fs_Mkfs_SingleParams_o_001.txt";
    int32_t fsckMkfsF2fsRes = ExecFsckWithOutput(device, F2fsMkfsFsckOutFileName);
    std::string HmfsMkfsFsckOutFileName = "/data/local/Fsck_Hmfs_Mkfs_SingleParams_o_001.txt";
    int32_t fsckMkfsHmfsRes = ExecFsckWithOutput(hmDevice, HmfsMkfsFsckOutFileName);
    ASSERT_EQ(fsckMkfsF2fsRes, fsckMkfsHmfsRes);
    ASSERT_TRUE(PrintFsckErrorMsg(HmfsMkfsFsckOutFileName, hmDevice));
    if (fsckMkfsHmfsRes == 0) {
        ASSERT_EQ(0, RemoveFile(HmfsMkfsFsckOutFileName));
        ASSERT_EQ(0, RemoveFile(F2fsMkfsFsckOutFileName));
    }

    // resize
    double overprovision = 60.0;
    std::vector<std::string> params;
    params.clear();
    params.push_back("-s");
    params.push_back("-t");
    params.push_back("102400");
    params.push_back("-o");
    params.push_back(std::to_string(overprovision));
    uint64_t f2fsRunTime = 0;
    uint64_t hmfsRunTime = 0;
    ASSERT_EQ(0, ExecResizeBinary(F2FS_TYPE, params, device, f2fsRunTime));
    std::cout << "----------------------------------------------------------------F2FS" << std::endl;
    PrintSuperBlockAndCheckPointData(device);
    ASSERT_EQ(0, ExecResizeBinary(HMFS_TYPE, params, hmDevice, hmfsRunTime));
    std::cout << "----------------------------------------------------------------HMFS" << std::endl;
    PrintSuperBlockAndCheckPointData(hmDevice);

    // 值校验
    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(device, f2fsSuperBlock);
    auto f2fsCheckPoint = std::make_unique<CheckPointData>();
    GetCheckPoint(device, f2fsCheckPoint);
    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(hmDevice, hmfsSuperBlock);
    auto hmfsCheckPoint = std::make_unique<CheckPointData>();
    GetCheckPoint(hmDevice, hmfsCheckPoint);
    ASSERT_EQ(f2fsCheckPoint->overprovisionSegmentCount, hmfsCheckPoint->overprovisionSegmentCount);
    ASSERT_EQ(f2fsCheckPoint->reservedSegmentCount, hmfsCheckPoint->reservedSegmentCount);
    std::cout << "overprovisionSegmentCount: " << f2fsCheckPoint->overprovisionSegmentCount << std::endl;
    std::cout << "reservedSegmentCount: " << f2fsCheckPoint->reservedSegmentCount << std::endl;
    uint32_t reservedSegments = (2 * (100 / overprovision + 1) + 6) * f2fsSuperBlock->segsPerSection;
    std::cout << "f2fsSuperBlock->segsPerSection: " << f2fsSuperBlock->segsPerSection << std::endl;
    std::cout << "校验-o参数 reservedSegments = " << reservedSegments << std::endl;
    uint32_t overprov_segment_count = (f2fsSuperBlock->segmentCountInMain - reservedSegments) * overprovision / 100;
    overprov_segment_count = overprov_segment_count + reservedSegments;
    std::cout << "校验-o参数 overprov_segment_count = " << overprov_segment_count << std::endl;
    ASSERT_EQ(hmfsCheckPoint->overprovisionSegmentCount, overprov_segment_count);
    ASSERT_EQ(hmfsCheckPoint->reservedSegmentCount, reservedSegments);

    //fsck check
    std::string HmfsFsckOutFileName = "/data/local/Fsck_Hmfs_SingleParams_o_001.txt";
    std::string F2fsFsckOutFileName = "/data/local/Fsck_F2fs_SingleParams_o_001.txt";
    int32_t fsckF2fsRes = ExecFsckWithOutput(device, F2fsFsckOutFileName);
    int32_t fsckHmfsRes = ExecFsckWithOutput(hmDevice, HmfsFsckOutFileName);
    ASSERT_EQ(fsckF2fsRes, fsckHmfsRes);
    ASSERT_TRUE(PrintFsckErrorMsg(HmfsFsckOutFileName, hmDevice));
    if (fsckHmfsRes == 0) {
        ASSERT_EQ(0, RemoveFile(HmfsFsckOutFileName));
        ASSERT_EQ(0, RemoveFile(F2fsFsckOutFileName));
    }
    ASSERT_EQ(FsBinaryCompare(device, hmDevice), 0);
    ASSERT_EQ(FsResultCompare(device, hmDevice), 0);
    (void)CompareRunTime(f2fsRunTime, hmfsRunTime);
    std::cout << "ResizeHmfsSingleTest_o_001 END" << std::endl;
}

/*
 * @tc.name: ResizeHmfsSingleTest_o_002
 * @tc.desc: test for resize hmfs.
 * @tc.type: FUNC
 */
HWTEST_F(ResizeHmfsSingleTest, ResizeHmfsSingleTest_o_002, TestSize.Level1)
{
    std::cout << "ResizeHmfsSingleTest_o_002 BEGIN" << std::endl;
    std::string device = F2FS_DEVICE;
    ExecutableDdCmd(device, 1000);
    ASSERT_EQ(0, ExecMkfsBinary(F2FS_TYPE, device));
    std::string hmDevice = HMFS_DEVICE;
    ExecutableDdCmd(hmDevice, 1000);
    ASSERT_EQ(0, ExecMkfsBinary(HMFS_TYPE, hmDevice));

    // mkfs fsck check
    std::string F2fsMkfsFsckOutFileName = "/data/local/Fsck_F2fs_Mkfs_SingleParams_o_002.txt";
    int32_t fsckMkfsF2fsRes = ExecFsckWithOutput(device, F2fsMkfsFsckOutFileName);
    std::string HmfsMkfsFsckOutFileName = "/data/local/Fsck_Hmfs_Mkfs_SingleParams_o_002.txt";
    int32_t fsckMkfsHmfsRes = ExecFsckWithOutput(hmDevice, HmfsMkfsFsckOutFileName);
    ASSERT_EQ(fsckMkfsF2fsRes, fsckMkfsHmfsRes);
    ASSERT_TRUE(PrintFsckErrorMsg(HmfsMkfsFsckOutFileName, hmDevice));
    if (fsckMkfsHmfsRes == 0) {
        ASSERT_EQ(0, RemoveFile(HmfsMkfsFsckOutFileName));
        ASSERT_EQ(0, RemoveFile(F2fsMkfsFsckOutFileName));
    }

    // resize
    double overprovision = 60.0;
    std::vector<std::string> params;
    params.clear();
    params.push_back("-s");
    params.push_back("-t");
    params.push_back("1024000");
    params.push_back("-o");
    params.push_back(std::to_string(overprovision));
    uint64_t f2fsRunTime = 0;
    uint64_t hmfsRunTime = 0;
    ASSERT_EQ(0, ExecResizeBinary(F2FS_TYPE, params, device, f2fsRunTime));
    std::cout << "----------------------------------------------------------------F2FS" << std::endl;
    PrintSuperBlockAndCheckPointData(device);
    ASSERT_EQ(0, ExecResizeBinary(HMFS_TYPE, params, hmDevice, hmfsRunTime));
    std::cout << "----------------------------------------------------------------HMFS" << std::endl;
    PrintSuperBlockAndCheckPointData(hmDevice);

    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(device, f2fsSuperBlock);
    auto f2fsCheckPoint = std::make_unique<CheckPointData>();
    GetCheckPoint(device, f2fsCheckPoint);
    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(hmDevice, hmfsSuperBlock);
    auto hmfsCheckPoint = std::make_unique<CheckPointData>();
    GetCheckPoint(hmDevice, hmfsCheckPoint);
    ASSERT_EQ(f2fsCheckPoint->overprovisionSegmentCount, hmfsCheckPoint->overprovisionSegmentCount);
    ASSERT_EQ(f2fsCheckPoint->reservedSegmentCount, hmfsCheckPoint->reservedSegmentCount);
    uint32_t reservedSegments = (2 * (100 / overprovision + 1) + 6) * f2fsSuperBlock->segsPerSection;
    std::cout << "f2fsSuperBlock->segsPerSection: " << f2fsSuperBlock->segsPerSection << std::endl;
    std::cout << "校验-o参数 reservedSegments = " << reservedSegments << std::endl;
    uint32_t overprov_segment_count = (f2fsSuperBlock->segmentCountInMain - reservedSegments) * overprovision / 100;
    overprov_segment_count = overprov_segment_count + reservedSegments;
    std::cout << "校验-o参数 overprov_segment_count = " << overprov_segment_count << std::endl;
    ASSERT_EQ(hmfsCheckPoint->overprovisionSegmentCount, overprov_segment_count);
    ASSERT_EQ(hmfsCheckPoint->reservedSegmentCount, reservedSegments);

    //fsck check
    std::string HmfsFsckOutFileName = "/data/local/Fsck_Hmfs_SingleParams_o_002.txt";
    std::string F2fsFsckOutFileName = "/data/local/Fsck_F2fs_SingleParams_o_002.txt";
    int32_t fsckF2fsRes = ExecFsckWithOutput(device, F2fsFsckOutFileName);
    int32_t fsckHmfsRes = ExecFsckWithOutput(hmDevice, HmfsFsckOutFileName);
    ASSERT_EQ(fsckF2fsRes, fsckHmfsRes);
    ASSERT_TRUE(PrintFsckErrorMsg(HmfsFsckOutFileName, hmDevice));
    if (fsckHmfsRes == 0) {
        ASSERT_EQ(0, RemoveFile(HmfsFsckOutFileName));
        ASSERT_EQ(0, RemoveFile(F2fsFsckOutFileName));
    }
    ASSERT_EQ(FsBinaryCompare(device, hmDevice), 0);
    ASSERT_EQ(FsResultCompare(device, hmDevice), 0);
    (void)CompareRunTime(f2fsRunTime, hmfsRunTime);
    std::cout << "ResizeHmfsSingleTest_o_002 END" << std::endl;
}

/*
 * @tc.name: ResizeHmfs_Abnormal__o_003
 * @tc.desc: test for resize hmfs.
 * @tc.type: FUNC
 */
HWTEST_F(ResizeHmfsSingleTest, ResizeHmfs_Abnormal_o_003, TestSize.Level1)
{
    std::cout << "ResizeHmfs_Abnormal_o_003 BEGIN" << std::endl;
    std::string device = F2FS_DEVICE;
    ExecutableDdCmd(device, 100);
    ASSERT_EQ(0, ExecMkfsBinary(HMFS_TYPE, device));

    std::vector<std::string> params;
    params.clear();
    params.push_back("-s");
    params.push_back("-t");
    params.push_back("102400");
    params.push_back("-o");
    params.push_back("1");
    std::string outputFile = "/data/local/test_output.txt";
    ASSERT_EQ(0, ExecResizeBinaryWithOutput(HMFS_TYPE, params, device, outputFile));
    std::cout << "----------------------------------------------------------------HMFS" << std::endl;
    PrintSuperBlockAndCheckPointData(device);

    std::string output = ReadFile(outputFile);
    ASSERT_TRUE(output.find("Error: Device size is not sufficient for HMFS volume, more segment needed") != std::string::npos);
    ASSERT_EQ(0, RemoveFile(outputFile));
    std::cout << "ResizeHmfs_Abnormal_o_003 END" << std::endl;
}

/*
 * @tc.name: ResizeHmfsSingleTest_o_004
 * @tc.desc: test for resize hmfs.
 * @tc.type: FUNC
 */
HWTEST_F(ResizeHmfsSingleTest, ResizeHmfsSingleTest_o_004, TestSize.Level1)
{
    std::cout << "ResizeHmfsSingleTest_o_005 BEGIN" << std::endl;
    std::string device = F2FS_DEVICE;
    ExecutableDdCmd(device, 100);
    ASSERT_EQ(0, ExecMkfsBinary(F2FS_TYPE, device));
    std::string hmDevice = HMFS_DEVICE;
    ExecutableDdCmd(hmDevice, 100);
    ASSERT_EQ(0, ExecMkfsBinary(HMFS_TYPE, hmDevice));

    // mkfs fsck check
    std::string F2fsMkfsFsckOutFileName = "/data/local/Fsck_F2fs_Mkfs_ResizeHmfsSingleTest_o_004.txt";
    int32_t fsckMkfsF2fsRes = ExecFsckWithOutput(device, F2fsMkfsFsckOutFileName);
    std::string HmfsMkfsFsckOutFileName = "/data/local/Fsck_Hmfs_Mkfs_ResizeHmfsSingleTest_o_004.txt";
    int32_t fsckMkfsHmfsRes = ExecFsckWithOutput(hmDevice, HmfsMkfsFsckOutFileName);
    ASSERT_EQ(fsckMkfsF2fsRes, fsckMkfsHmfsRes);
    ASSERT_TRUE(PrintFsckErrorMsg(HmfsMkfsFsckOutFileName, hmDevice));
    if (fsckMkfsHmfsRes == 0) {
        ASSERT_EQ(0, RemoveFile(HmfsMkfsFsckOutFileName));
        ASSERT_EQ(0, RemoveFile(F2fsMkfsFsckOutFileName));
    }

    // resize
    double overprovision = 0.0;
    std::vector<std::string> params;
    params.clear();
    params.push_back("-s");
    params.push_back("-t");
    params.push_back("102400");
    params.push_back("-o");
    params.push_back("0");
    uint64_t f2fsRunTime = 0;
    uint64_t hmfsRunTime = 0;
    ASSERT_EQ(0, ExecResizeBinary(F2FS_TYPE, params, device, f2fsRunTime));
    std::cout << "----------------------------------------------------------------F2FS" << std::endl;
    PrintSuperBlockAndCheckPointData(device);
    ASSERT_EQ(0, ExecResizeBinary(HMFS_TYPE, params, hmDevice, hmfsRunTime));
    std::cout << "----------------------------------------------------------------HMFS" << std::endl;
    PrintSuperBlockAndCheckPointData(hmDevice);

    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(device, f2fsSuperBlock);
    auto f2fsCheckPoint = std::make_unique<CheckPointData>();
    GetCheckPoint(device, f2fsCheckPoint);
    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(hmDevice, hmfsSuperBlock);
    auto hmfsCheckPoint = std::make_unique<CheckPointData>();
    GetCheckPoint(hmDevice, hmfsCheckPoint);
    overprovision = HmfsCommon::GetInstance().GetBestOverProvision(hmfsSuperBlock.get());
    ASSERT_EQ(f2fsCheckPoint->overprovisionSegmentCount, hmfsCheckPoint->overprovisionSegmentCount);
    ASSERT_EQ(f2fsCheckPoint->reservedSegmentCount, hmfsCheckPoint->reservedSegmentCount);
    uint32_t reservedSegments = (2 * (100 / overprovision + 1) + 6) * f2fsSuperBlock->segsPerSection;
    std::cout << "f2fsSuperBlock->segsPerSection: " << f2fsSuperBlock->segsPerSection << std::endl;
    std::cout << "校验-o参数 reservedSegments = " << reservedSegments << std::endl;
    uint32_t overprov_segment_count = (f2fsSuperBlock->segmentCountInMain - reservedSegments) * overprovision / 100;
    overprov_segment_count = overprov_segment_count + reservedSegments;
    std::cout << "校验-o参数 overprov_segment_count = " << overprov_segment_count << std::endl;
    ASSERT_EQ(hmfsCheckPoint->overprovisionSegmentCount, overprov_segment_count);
    ASSERT_EQ(hmfsCheckPoint->reservedSegmentCount, reservedSegments);

    //fsck check
    std::string HmfsFsckOutFileName = "/data/local/Fsck_Hmfs_SingleParams_o_004.txt";
    std::string F2fsFsckOutFileName = "/data/local/Fsck_F2fs_SingleParams_o_004.txt";
    int32_t fsckF2fsRes = ExecFsckWithOutput(device, F2fsFsckOutFileName);
    int32_t fsckHmfsRes = ExecFsckWithOutput(hmDevice, HmfsFsckOutFileName);
    ASSERT_EQ(fsckF2fsRes, fsckHmfsRes);
    ASSERT_TRUE(PrintFsckErrorMsg(HmfsFsckOutFileName, hmDevice));
    if (fsckHmfsRes == 0) {
        ASSERT_EQ(0, RemoveFile(HmfsFsckOutFileName));
        ASSERT_EQ(0, RemoveFile(F2fsFsckOutFileName));
    }
    ASSERT_EQ(FsBinaryCompare(device, hmDevice), 0);
    ASSERT_EQ(FsResultCompare(device, hmDevice), 0);
    (void)CompareRunTime(f2fsRunTime, hmfsRunTime);
    std::cout << "ResizeHmfsSingleTest_o_004 END" << std::endl;
}

/*
 * @tc.name: ResizeHmfsSingleTest_o_005
 * @tc.desc: test for resize hmfs.
 * @tc.type: FUNC
 */
HWTEST_F(ResizeHmfsSingleTest, ResizeHmfsSingleTest_o_005, TestSize.Level1)
{
    std::cout << "ResizeHmfsSingleTest_o_006 BEGIN" << std::endl;
    std::string device = F2FS_DEVICE;
    ExecutableDdCmd(device, 100);
    ASSERT_EQ(0, ExecMkfsBinary(F2FS_TYPE, device));
    std::string hmDevice = HMFS_DEVICE;
    ExecutableDdCmd(hmDevice, 100);
    ASSERT_EQ(0, ExecMkfsBinary(HMFS_TYPE, hmDevice));

    // mkfs fsck check
    std::string F2fsMkfsFsckOutFileName = "/data/local/Fsck_F2fs_Mkfs_ResizeHmfsSingleTest_o_005.txt";
    int32_t fsckMkfsF2fsRes = ExecFsckWithOutput(device, F2fsMkfsFsckOutFileName);
    std::string HmfsMkfsFsckOutFileName = "/data/local/Fsck_Hmfs_Mkfs_ResizeHmfsSingleTest_o_005.txt";
    int32_t fsckMkfsHmfsRes = ExecFsckWithOutput(hmDevice, HmfsMkfsFsckOutFileName);
    ASSERT_EQ(fsckMkfsF2fsRes, fsckMkfsHmfsRes);
    ASSERT_TRUE(PrintFsckErrorMsg(HmfsMkfsFsckOutFileName, hmDevice));
    if (fsckMkfsHmfsRes == 0) {
        ASSERT_EQ(0, RemoveFile(HmfsMkfsFsckOutFileName));
        ASSERT_EQ(0, RemoveFile(F2fsMkfsFsckOutFileName));
    }

    // resize
    std::vector<std::string> params;
    params.clear();
    params.push_back("-s");
    params.push_back("-t");
    params.push_back("102400");
    params.push_back("-o");
    params.push_back("1000");
    uint64_t f2fsRunTime = 0;
    uint64_t hmfsRunTime = 0;
    ASSERT_EQ(0, ExecResizeBinary(F2FS_TYPE, params, device, f2fsRunTime));
    std::cout << "----------------------------------------------------------------F2FS" << std::endl;
    PrintSuperBlockAndCheckPointData(device);
    ASSERT_EQ(0, ExecResizeBinary(HMFS_TYPE, params, hmDevice, hmfsRunTime));
    std::cout << "----------------------------------------------------------------HMFS" << std::endl;
    PrintSuperBlockAndCheckPointData(hmDevice);

    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(device, f2fsSuperBlock);
    auto f2fsCheckPoint = std::make_unique<CheckPointData>();
    GetCheckPoint(device, f2fsCheckPoint);
    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(hmDevice, hmfsSuperBlock);
    auto hmfsCheckPoint = std::make_unique<CheckPointData>();
    GetCheckPoint(hmDevice, hmfsCheckPoint);
    ASSERT_EQ(f2fsCheckPoint->overprovisionSegmentCount, hmfsCheckPoint->overprovisionSegmentCount);
    ASSERT_EQ(f2fsCheckPoint->reservedSegmentCount, hmfsCheckPoint->reservedSegmentCount);

    //fsck check
    std::string HmfsFsckOutFileName = "/data/local/Fsck_Hmfs_SingleParams_o_005.txt";
    std::string F2fsFsckOutFileName = "/data/local/Fsck_F2fs_SingleParams_o_005.txt";
    int32_t fsckF2fsRes = ExecFsckWithOutput(device, F2fsFsckOutFileName);
    int32_t fsckHmfsRes = ExecFsckWithOutput(hmDevice, HmfsFsckOutFileName);
    ASSERT_EQ(fsckF2fsRes, fsckHmfsRes);
    ASSERT_TRUE(PrintFsckErrorMsg(HmfsFsckOutFileName, hmDevice));
    if (fsckHmfsRes == 0) {
        ASSERT_EQ(0, RemoveFile(HmfsFsckOutFileName));
        ASSERT_EQ(0, RemoveFile(F2fsFsckOutFileName));
    }
    ASSERT_EQ(FsBinaryCompare(device, hmDevice), 0);
    ASSERT_EQ(FsResultCompare(device, hmDevice), 0);
    (void)CompareRunTime(f2fsRunTime, hmfsRunTime);
    std::cout << "ResizeHmfsSingleTest_o_005 END" << std::endl;
}

/*
 * @tc.name: ResizeHmfsSingleTest_o_006
 * @tc.desc: test for resize hmfs.
 * @tc.type: FUNC
 */
HWTEST_F(ResizeHmfsSingleTest, ResizeHmfsSingleTest_o_006, TestSize.Level1)
{
    std::cout << "ResizeHmfsSingleTest_o_006 BEGIN" << std::endl;
    std::string device = F2FS_DEVICE;
    ExecutableDdCmd(device, 100);
    ASSERT_EQ(0, ExecMkfsBinary(F2FS_TYPE, device));
    std::string hmDevice = HMFS_DEVICE;
    ExecutableDdCmd(hmDevice, 100);
    ASSERT_EQ(0, ExecMkfsBinary(HMFS_TYPE, hmDevice));

    // mkfs fsck check
    std::string F2fsMkfsFsckOutFileName = "/data/local/Fsck_F2fs_Mkfs_ResizeHmfsSingleTest_o_006.txt";
    int32_t fsckMkfsF2fsRes = ExecFsckWithOutput(device, F2fsMkfsFsckOutFileName);
    std::string HmfsMkfsFsckOutFileName = "/data/local/Fsck_Hmfs_Mkfs_ResizeHmfsSingleTest_o_006.txt";
    int32_t fsckMkfsHmfsRes = ExecFsckWithOutput(hmDevice, HmfsMkfsFsckOutFileName);
    ASSERT_EQ(fsckMkfsF2fsRes, fsckMkfsHmfsRes);
    ASSERT_TRUE(PrintFsckErrorMsg(HmfsMkfsFsckOutFileName, hmDevice));
    if (fsckMkfsHmfsRes == 0) {
        ASSERT_EQ(0, RemoveFile(HmfsMkfsFsckOutFileName));
        ASSERT_EQ(0, RemoveFile(F2fsMkfsFsckOutFileName));
    }

    std::vector<std::string> params;
    params.clear();
    params.push_back("-s");
    params.push_back("-t");
    params.push_back("102400");
    params.push_back("-o");
    params.push_back("-1000");
    uint64_t f2fsRunTime = 0;
    uint64_t hmfsRunTime = 0;
    ASSERT_EQ(0, ExecResizeBinary(F2FS_TYPE, params, device, f2fsRunTime));
    std::cout << "----------------------------------------------------------------F2FS" << std::endl;
    PrintSuperBlockAndCheckPointData(device);
    ASSERT_EQ(0, ExecResizeBinary(HMFS_TYPE, params, hmDevice, hmfsRunTime));
    std::cout << "----------------------------------------------------------------HMFS" << std::endl;
    PrintSuperBlockAndCheckPointData(hmDevice);

    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(device, f2fsSuperBlock);
    auto f2fsCheckPoint = std::make_unique<CheckPointData>();
    GetCheckPoint(device, f2fsCheckPoint);
    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(hmDevice, hmfsSuperBlock);
    auto hmfsCheckPoint = std::make_unique<CheckPointData>();
    GetCheckPoint(hmDevice, hmfsCheckPoint);
    ASSERT_EQ(f2fsCheckPoint->overprovisionSegmentCount, hmfsCheckPoint->overprovisionSegmentCount);
    ASSERT_EQ(f2fsCheckPoint->reservedSegmentCount, hmfsCheckPoint->reservedSegmentCount);

    //fsck check
    std::string HmfsFsckOutFileName = "/data/local/Fsck_Hmfs_SingleParams_o_006.txt";
    std::string F2fsFsckOutFileName = "/data/local/Fsck_F2fs_SingleParams_o_006.txt";
    int32_t fsckF2fsRes = ExecFsckWithOutput(device, F2fsFsckOutFileName);
    int32_t fsckHmfsRes = ExecFsckWithOutput(hmDevice, HmfsFsckOutFileName);
    ASSERT_EQ(fsckF2fsRes, fsckHmfsRes);
    ASSERT_TRUE(PrintFsckErrorMsg(HmfsFsckOutFileName, hmDevice));
    if (fsckHmfsRes == 0) {
        ASSERT_EQ(0, RemoveFile(HmfsFsckOutFileName));
        ASSERT_EQ(0, RemoveFile(F2fsFsckOutFileName));
    }
    ASSERT_EQ(FsBinaryCompare(device, hmDevice), 0);
    ASSERT_EQ(FsResultCompare(device, hmDevice), 0);
    (void)CompareRunTime(f2fsRunTime, hmfsRunTime);
    std::cout << "ResizeHmfsSingleTest_o_006 END" << std::endl;
}

/*
 * @tc.name: ResizeHmfsSingleTest_i_001
 * @tc.desc: test for resize hmfs.
 * @tc.type: FUNC
 */
HWTEST_F(ResizeHmfsSingleTest, ResizeHmfsSingleTest_i_001, TestSize.Level1)
{
    std::cout << "ResizeHmfsSingleTest_i_001 BEGIN" << std::endl;
    std::string device = F2FS_DEVICE;
    ExecutableDdCmd(device, 100);
    ASSERT_EQ(0, ExecMkfsBinary(F2FS_TYPE, device));
    std::string hmDevice = HMFS_DEVICE;
    ExecutableDdCmd(hmDevice, 100);
    ASSERT_EQ(0, ExecMkfsBinary(HMFS_TYPE, hmDevice));

    // mkfs fsck check
    std::string F2fsMkfsFsckOutFileName = "/data/local/Fsck_F2fs_Mkfs_ResizeHmfsSingleTest_i_001.txt";
    int32_t fsckMkfsF2fsRes = ExecFsckWithOutput(device, F2fsMkfsFsckOutFileName);
    std::string HmfsMkfsFsckOutFileName = "/data/local/Fsck_Hmfs_Mkfs_ResizeHmfsSingleTest_i_001.txt";
    int32_t fsckMkfsHmfsRes = ExecFsckWithOutput(hmDevice, HmfsMkfsFsckOutFileName);
    ASSERT_EQ(fsckMkfsF2fsRes, fsckMkfsHmfsRes);
    ASSERT_TRUE(PrintFsckErrorMsg(HmfsMkfsFsckOutFileName, hmDevice));
    if (fsckMkfsHmfsRes == 0) {
        ASSERT_EQ(0, RemoveFile(HmfsMkfsFsckOutFileName));
        ASSERT_EQ(0, RemoveFile(F2fsMkfsFsckOutFileName));
    }

    std::vector<std::string> params;
    params.clear();
    params.push_back("-s");
    params.push_back("-t");
    params.push_back("102400");
    params.push_back("-i");
    std::string outputFile = "/data/local/test_output.txt";
    uint64_t f2fsRunTime = 0;
    uint64_t hmfsRunTime = 0;
    ASSERT_EQ(0, ExecResizeBinary(F2FS_TYPE, params, device, f2fsRunTime));
    std::cout << "----------------------------------------------------------------F2FS" << std::endl;
    PrintSuperBlockAndCheckPointData(device);
    ASSERT_EQ(0, ExecResizeBinary(HMFS_TYPE, params, hmDevice, hmfsRunTime));
    std::cout << "----------------------------------------------------------------HMFS" << std::endl;
    PrintSuperBlockAndCheckPointData(hmDevice);

    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(device, f2fsSuperBlock);
    auto f2fsCheckPoint = std::make_unique<CheckPointData>();
    GetCheckPoint(device, f2fsCheckPoint);
    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(hmDevice, hmfsSuperBlock);
    auto hmfsCheckPoint = std::make_unique<CheckPointData>();
    GetCheckPoint(hmDevice, hmfsCheckPoint);

    //fsck check
    std::string HmfsFsckOutFileName = "/data/local/Fsck_Hmfs_SingleParams_i_001.txt";
    std::string F2fsFsckOutFileName = "/data/local/Fsck_F2fs_SingleParams_i_001.txt";
    int32_t fsckF2fsRes = ExecFsckWithOutput(device, F2fsFsckOutFileName);
    int32_t fsckHmfsRes = ExecFsckWithOutput(hmDevice, HmfsFsckOutFileName);
    ASSERT_TRUE(PrintFsckErrorMsg(HmfsFsckOutFileName, hmDevice));
    if (fsckF2fsRes == fsckHmfsRes && fsckHmfsRes == 0) {
        ASSERT_EQ(0, RemoveFile(HmfsFsckOutFileName));
        ASSERT_EQ(0, RemoveFile(F2fsFsckOutFileName));
    }
    ASSERT_EQ(FsBinaryCompare(device, hmDevice), 0);
    ASSERT_EQ(FsResultCompare(device, hmDevice), 0);
    (void)CompareRunTime(f2fsRunTime, hmfsRunTime);
    std::cout << "ResizeHmfsSingleTest_i_001 END" << std::endl;
}

/*
 * @tc.name: ResizeHmfsSingleTest_i_002
 * @tc.desc: test for resize hmfs.
 * @tc.type: FUNC
 */
HWTEST_F(ResizeHmfsSingleTest, ResizeHmfsSingleTest_i_002, TestSize.Level1)
{
    std::cout << "ResizeHmfsSingleTest_i_002 BEGIN" << std::endl;
    std::string device = F2FS_DEVICE;
    ExecutableDdCmd(device, 1000);
    ASSERT_EQ(0, ExecMkfsBinary(F2FS_TYPE, device));
    std::string hmDevice = HMFS_DEVICE;
    ExecutableDdCmd(hmDevice, 1000);
    ASSERT_EQ(0, ExecMkfsBinary(HMFS_TYPE, hmDevice));

    // mkfs fsck check
    std::string F2fsMkfsFsckOutFileName = "/data/local/Fsck_F2fs_Mkfs_ResizeHmfsSingleTest_i_001.txt";
    int32_t fsckMkfsF2fsRes = ExecFsckWithOutput(device, F2fsMkfsFsckOutFileName);
    std::string HmfsMkfsFsckOutFileName = "/data/local/Fsck_Hmfs_Mkfs_ResizeHmfsSingleTest_i_001.txt";
    int32_t fsckMkfsHmfsRes = ExecFsckWithOutput(hmDevice, HmfsMkfsFsckOutFileName);
    ASSERT_EQ(fsckMkfsF2fsRes, fsckMkfsHmfsRes);
    ASSERT_TRUE(PrintFsckErrorMsg(HmfsMkfsFsckOutFileName, hmDevice));
    if (fsckMkfsHmfsRes == 0) {
        ASSERT_EQ(0, RemoveFile(HmfsMkfsFsckOutFileName));
        ASSERT_EQ(0, RemoveFile(F2fsMkfsFsckOutFileName));
    }

    // resize
    std::vector<std::string> params;
    params.clear();
    params.push_back("-s");
    params.push_back("-t");
    params.push_back("1024000");
    params.push_back("-i");
    std::string outputFile = "/data/local/test_output.txt";
    uint64_t f2fsRunTime = 0;
    uint64_t hmfsRunTime = 0;
    ASSERT_EQ(0, ExecResizeBinary(F2FS_TYPE, params, device, f2fsRunTime));
    std::cout << "----------------------------------------------------------------F2FS" << std::endl;
    PrintSuperBlockAndCheckPointData(device);
    ASSERT_EQ(0, ExecResizeBinary(HMFS_TYPE, params, hmDevice, hmfsRunTime));
    std::cout << "----------------------------------------------------------------HMFS" << std::endl;
    PrintSuperBlockAndCheckPointData(hmDevice);

    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(device, f2fsSuperBlock);
    auto f2fsCheckPoint = std::make_unique<CheckPointData>();
    GetCheckPoint(device, f2fsCheckPoint);
    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(hmDevice, hmfsSuperBlock);
    auto hmfsCheckPoint = std::make_unique<CheckPointData>();
    GetCheckPoint(hmDevice, hmfsCheckPoint);

    //fsck check
    std::string HmfsFsckOutFileName = "/data/local/Fsck_Hmfs_SingleParams_o_004.txt";
    std::string F2fsFsckOutFileName = "/data/local/Fsck_F2fs_SingleParams_o_004.txt";
    int32_t fsckF2fsRes = ExecFsckWithOutput(device, F2fsFsckOutFileName);
    int32_t fsckHmfsRes = ExecFsckWithOutput(hmDevice, HmfsFsckOutFileName);
    ASSERT_TRUE(PrintFsckErrorMsg(HmfsFsckOutFileName, hmDevice));
    if (fsckF2fsRes == fsckHmfsRes && fsckHmfsRes == 0) {
        ASSERT_EQ(0, RemoveFile(HmfsFsckOutFileName));
        ASSERT_EQ(0, RemoveFile(F2fsFsckOutFileName));
    }
    ASSERT_EQ(FsBinaryCompare(device, hmDevice), 0);
    ASSERT_EQ(FsResultCompare(device, hmDevice), 0);
    (void)CompareRunTime(f2fsRunTime, hmfsRunTime);
    std::cout << "ResizeHmfsSingleTest_i_002 END" << std::endl;
}

/*
 * @tc.name: ResizeHmfsSingleTest_d_001
 * @tc.desc: test for resize hmfs.
 * @tc.type: FUNC
 */
HWTEST_F(ResizeHmfsSingleTest, ResizeHmfsSingleTest_d_001, TestSize.Level1)
{
    std::cout << "ResizeHmfsSingleTest_d_001 BEGIN" << std::endl;
    std::string device = HMFS_DEVICE;
    ExecutableDdCmd(device, 100);
    ASSERT_EQ(0, ExecMkfsBinary(HMFS_TYPE, device));

    std::vector<std::string> params;
    params.clear();
    params.push_back("-s");
    params.push_back("-t");
    params.push_back("102400");
    params.push_back("-d");
    params.push_back("0");
    std::string outputFile = "/data/local/test_output.txt";
    ASSERT_EQ(0, ExecResizeBinaryWithOutput(HMFS_TYPE, params, device, outputFile));
    std::string output = ReadFile(outputFile);
    ASSERT_EQ(0, RemoveFile(outputFile));
    std::cout << "ResizeHmfsSingleTest_d_001 END" << std::endl;
}

/*
 * @tc.name: ResizeHmfsSingleTest_d_002
 * @tc.desc: test for resize hmfs.
 * @tc.type: FUNC
 */
HWTEST_F(ResizeHmfsSingleTest, ResizeHmfsSingleTest_d_002, TestSize.Level1)
{
    std::cout << "ResizeHmfsSingleTest_d_002 BEGIN" << std::endl;
    std::string device = HMFS_DEVICE;
    ExecutableDdCmd(device, 100);
    ASSERT_EQ(0, ExecMkfsBinary(HMFS_TYPE, device));

    std::vector<std::string> params;
    params.clear();
    params.push_back("-s");
    params.push_back("-t");
    params.push_back("102400");
    params.push_back("-d");
    params.push_back("1");
    std::string outputFile = "/data/local/test_output.txt";
    ASSERT_EQ(0, ExecResizeBinaryWithOutput(HMFS_TYPE, params, device, outputFile));
    std::string output = ReadFile(outputFile);

    std::cout << "----------------------------------------------------------------HMFS" << std::endl;
    PrintSuperBlockAndCheckPointData(device);
    ASSERT_EQ(0, RemoveFile(outputFile));
    // ASSERT_TRUE(output.find("Info: Debug level = 1") != std::string::npos);
    std::cout << "ResizeHmfsSingleTest_d_002 END" << std::endl;
}

/*
 * @tc.name: ResizeHmfsSingleTest_d_003
 * @tc.desc: test for resize hmfs.
 * @tc.type: FUNC
 */
HWTEST_F(ResizeHmfsSingleTest, ResizeHmfsSingleTest_d_003, TestSize.Level1)
{
    std::cout << "ResizeHmfsSingleTest_d_003 BEGIN" << std::endl;
    std::string device = HMFS_DEVICE;
    ExecutableDdCmd(device, 100);
    ASSERT_EQ(0, ExecMkfsBinary(HMFS_TYPE, device));

    std::vector<std::string> params;
    params.clear();
    params.push_back("-s");
    params.push_back("-t");
    params.push_back("102400");
    params.push_back("-d");
    params.push_back("10");
    std::string outputFile = "/data/local/test_output.txt";
    ASSERT_EQ(0, ExecResizeBinaryWithOutput(HMFS_TYPE, params, device, outputFile));
    std::cout << "----------------------------------------------------------------HMFS" << std::endl;
    PrintSuperBlockAndCheckPointData(device);

    std::string output = ReadFile(outputFile);
    // ASSERT_TRUE(output.find("Info: Debug level = 10") != std::string::npos);
    ASSERT_EQ(0, RemoveFile(outputFile));
    std::cout << "ResizeHmfsSingleTest_d_003 END" << std::endl;
}

/*
 * @tc.name: ResizeHmfs_Abnormal_d_004
 * @tc.desc: test for resize hmfs.
 * @tc.type: FUNC
 */
HWTEST_F(ResizeHmfsSingleTest, ResizeHmfs_Abnormal_d_004, TestSize.Level1)
{
    std::cout << "ResizeHmfs_Abnormal_d_004 BEGIN" << std::endl;
    std::string device = HMFS_DEVICE;
    ExecutableDdCmd(device, 100);
    ASSERT_EQ(0, ExecMkfsBinary(HMFS_TYPE, device));

    std::vector<std::string> params;
    params.clear();
    params.push_back("-s");
    params.push_back("-t");
    params.push_back("102400");
    params.push_back("-d");
    params.push_back("-1");
    ASSERT_NE(0, ExecResizeBinary(HMFS_TYPE, params, device));
    std::cout << "ResizeHmfs_Abnormal_d_004 END" << std::endl;
}

/*
 * @tc.name: ResizeHmfsSingleTest_f_001
 * @tc.desc: test for resize hmfs.
 * @tc.type: FUNC
 */
HWTEST_F(ResizeHmfsSingleTest, ResizeHmfsSingleTest_f_001, TestSize.Level1)
{
    std::cout << "ResizeHmfsSingleTest_f_001 BEGIN" << std::endl;
    std::string device = HMFS_DEVICE;
    ExecutableDdCmd(device, 100);
    ASSERT_EQ(0, ExecMkfsBinary(HMFS_TYPE, device));

    std::vector<std::string> params;
    params.clear();
    params.push_back("-f");
    std::string outputFile = "/data/local/test_output.txt";
    ASSERT_EQ(0, ExecResizeBinaryWithOutput(HMFS_TYPE, params, device, outputFile));
    std::string output = ReadFile(outputFile);
    ASSERT_TRUE(output.find("Info: Done to rebuild checkpoint blocks") != std::string::npos);
    ASSERT_EQ(0, RemoveFile(outputFile));
    std::cout << "ResizeHmfsSingleTest_f_001 END" << std::endl;
}
} // namespace Hmfs
} // namespace OHOS